local biaoyong = fk.CreateSkill {
  name = "lingling__biaoyong",
}

Fk:loadTranslationTable{
  ["lingling__biaoyong"] = "飚勇",
  [":lingling__biaoyong"] = "出牌阶段，你可以将一张不为本阶段以此法获得的【杀】或武器牌当【穷寇勿迫】使用。",

  ["#lingling__biaoyong"] = "飚勇：你可以将【杀】或武器牌当【穷寇勿迫】使用",
}

biaoyong:addEffect("viewas", {
  anim_type = "offensive",
  mute_card = false,
  prompt = "#lingling__biaoyong",
  handly_pile = true,
  card_filter = function(self, player, to_select, selected)
    return #selected == 0 and
      (Fk:getCardById(to_select).trueName == "slash" or Fk:getCardById(to_select).sub_type == Card.SubtypeWeapon) and
      Fk:getCardById(to_select):getMark("lingling__biaoyong-inhand-phase") == 0
  end,
  view_as = function(self, player, cards)
    if #cards ~= 1 then return end
    local card = Fk:cloneCard("ling__stop_chasing")
    card.skillName = biaoyong.name
    card:addSubcard(cards[1])
    return card
  end,
})

biaoyong:addEffect(fk.AfterCardsMove, {
  can_refresh = function (self, event, target, player, data)
    if player:hasSkill(biaoyong.name, true) and player.phase == Player.Play then
      for _, move in ipairs(data) do
        if move.to == player and move.toArea == Card.PlayerHand and
          move.skillName == "ling__stop_chasing_skill" then
          local effect_event = player.room.logic:getCurrentEvent():findParent(GameEvent.CardEffect)
          if effect_event then
            local use = effect_event.data
            return table.contains(use.card.skillNames, biaoyong.name)
          end
        end
      end
    end
  end,
  on_refresh = function (self, event, target, player, data)
    for _, move in ipairs(data) do
      if move.to == player and move.toArea == Card.PlayerHand and
        move.skillName == "ling__stop_chasing_skill" then
        for _, info in ipairs(move.moveInfo) do
          local card = Fk:getCardById(info.cardId)
          if card.trueName == "slash" or card.sub_type == Card.SubtypeWeapon then
            player.room:setCardMark(card, "lingling__biaoyong-inhand-phase", 1)
          end
        end
      end
    end
  end,
})

biaoyong:addAI(nil, "vs_skill")

return biaoyong
